package gnippets.domain

import refcode.RefCode

/*
 * Copyright 2008 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
/**
 *  <p>Integration Tests for the comments</p>
 *
 *  @author <a href='mailto:kouphax@gmail.com'>James Hughes</a>
 */
class CommentTests extends GroovyTestCase {


    def predefinedUser
    
    //=========================================================================
    //
    //                    U N I T   T E S T   S E T   U P
    //
    //=========================================================================
    void setUp(){
        /* create a predefined user */
        predefinedUser = new GnippetsUser(
            username:'predefined',
            password:'password',
            realName:'Test User',
            email:'predefined@unittest.com'        
        )
        
        /* save predefined user */
        if(!predefinedUser.save()){
            throw new Exception("Error in setup method. Save user failed.");
        }    
    }
    
    //=========================================================================
    //
    //       C O M M E N T   T E X T   C O N S T R A I N T S   T E S T S
    //    
    //=========================================================================
    
    void testConstraintsCommentNull() {
    
        def testComment = new Comment(postDate : new Date())
        
        assert testComment.validate() == false
        
        testComment.comment = "Test Comment Text"
        
        assert testComment.validate() == true
    }    
    
    void testConstraintsCommentBlank() {
    
        def testComment = new Comment(postDate : new Date(), comment:'')
        
        assert testComment.validate() == false
        
        testComment.comment = "Test Comment Text"
        
        assert testComment.validate() == true
    }    
    
    //=========================================================================
    //
    //            P O S T   D A T E   C O N S T R A I N T S   T E S T S
    //    
    //=========================================================================    
    
    void testConstraintsPostDateNull() {
    
        def testComment = new Comment(comment:'Test Comment Text')
        
        assert testComment.validate() == true
        
        testComment.postDate = null
        
        assert testComment.validate() == false
    }       
  
}
